<project name="fengke" basedir=".">
	<property file="build.properties"/>
	<!-- some variables used -->
	<property name="project.name" value="fengke" />
	<property name="src.dir" value="src"/>
	<property name="test.dir" value="test"/>
	<property name="build.dir" value="build"/>
	<property name="output.dir" value="output"/>
	<property name="junit.reports.dir" location="build/junit_report"/>
	<property name="lib.dir" value="WebContent/WEB-INF/lib"/>
	<property name="servletApi.dir" value="servlet"/>
	<property name="classes.dir" value="build/classes"/>
	<property name="version" value="0.1-SNAPSHOT"/>

	<!-- paths used for compilation and run  -->
	<path id="compile.path.id">
		<fileset dir="${lib.dir}" includes="**/*.jar"/>
		<fileset dir="${servletApi.dir}" includes="**/*.jar"/>
		<path location="${classes.dir}"/>
	</path>
	
	<!--
		paths used for compilation and run test
	-->
	<path id="test.path.id">
		<fileset dir="${lib.dir}" includes="**/*.jar"/>
		<fileset dir="${servletApi.dir}" includes="**/*.jar"/>
		<path location="${classes.dir}"/>
	</path>

	<!--
	 | CLEAN:
	 |
	 | Cleans up the output directory for this project.
	 +-->
	<target name="clean" description="delete folder">
		<delete dir="${build.dir}" />
		<delete dir="${output.dir}" />
	</target>

	<!--
     |
     | INIT:
     |
     | Make directory for this project and copy libs for package.
     +-->
	<target name="init" depends="clean" description="create folder">
		<mkdir dir="${build.dir}/lib" />
		<mkdir dir="${output.dir}" />
		<copy todir="${build.dir}/lib" flatten="true">
			<fileset dir="${lib.dir}">
				<include name="**/*.jar" />
			</fileset>
		</copy>
	</target>

	<!--
	 | COMPILE:
	 |
	 | Run javac on all Java source.
	 +-->
	<target name="compile" depends="init" description="--> compile the source." >
		<echo message="--------------------------------------------------------------------" />
		<echo message=" Compiling Java classes..." />
		<echo message="--------------------------------------------------------------------" />
		<echo message="" />
		<mkdir dir="${classes.dir}" />
		<copy todir="${classes.dir}">
			<fileset dir="${src.dir}">
				<exclude name="**/*.java"/>
			</fileset>
		</copy>
		<javac encoding="${java.encoding}" destdir="${classes.dir}" classpathref="compile.path.id" debug="${build.debug}">
			<src path="${src.dir}"/>
		</javac>
	</target>


	<!--
	 | WAR:
	 |
	 | Pack the war.
	 +-->
	<target name="war" depends="compile" description="package application to war">
		<echo message="--------------------------------------------------------------------" />
		<echo message=" Packing war..." />
		<echo message="--------------------------------------------------------------------" />
		<echo message="" />
		<war warfile="${output.dir}/${project.name}.war" webxml="WebContent/WEB-INF/web.xml">
			<fileset dir="WebContent">
				<exclude name="WEB-INF/classes/**/*.*" />
				<exclude name="WEB-INF/lib/**/*.*" />
			</fileset>
			<lib dir="${build.dir}/lib" includes="*.jar"/>
			<classes dir="${classes.dir}" />
		</war>
	</target>




	<!--
	 | DEPLOY:
	 |
	 | Deploy the project to a directory.
	 +-->
	<target name="deploy" depends="war" description="--> deploy the project">
		<echo message="--------------------------------------------------------------------" />
		<echo message=" Deploying project..." />
		<echo message="--------------------------------------------------------------------" />
		<echo message="" />
		<delete file="${deploy.dir}/lycrm.war"/>
		<delete dir="${deploy.dir}/lycrm"/>
		<copy todir="${deploy.dir}" file="${output.dir}/${project.name}.war"/>
	</target>

	<target name="compile-test" depends="compile" description="--> compile the test cases.">
		<echo message="--------------------------------------------------------------------" />
		<echo message=" Compiling test..." />
		<echo message="--------------------------------------------------------------------" />
		<echo message="" />
		<copy todir="${classes.dir}">
			<fileset dir="${test.dir}">
				<include name="**/*.xml"/>
			</fileset>
		</copy>
		<javac srcdir="${test.dir}" destdir="${classes.dir}" classpathref="test.path.id" debug="true"/>
	</target>
			
	<!--
	 | RUN-TEST:
	 |
	 | Run the test.
	 +-->
	<target name="run-test" depends="compile-test" description="--> run the test cases.">
		<echo message="--------------------------------------------------------------------" />
		<echo message=" Running test..." />
		<echo message="--------------------------------------------------------------------" />
		<echo message="" />
		<property name="test.targetclasspath" value="${classes.dir}"/>
		<antcall target="test"/>
	</target>

	<!--
	 | TEST:
	 |
	 | JUnit test.
	 +-->
	<target name="test">
		<delete includeemptydirs="true" dir="${junit.reports.dir}"/>
		<mkdir dir="${junit.reports.dir}"/>
		<junit dir="${basedir}" fork="true" showoutput="true" failureproperty="tests.failed">
			<classpath location="${test.targetclasspath}"/>
			<classpath location="${classes.dir}"/>
			<classpath refid="test.path.id">
			</classpath>
			<formatter type="xml"/>
			<batchtest todir="${junit.reports.dir}">
				<fileset dir="${test.dir}">
					<include name="**/*Test.java"/>
				</fileset>
			</batchtest>
		</junit>
		<junitreport todir="${junit.reports.dir}">
			<fileset dir="${junit.reports.dir}">
				<include name="TEST-*.xml"/>
			</fileset>
			<report format="frames" todir="${junit.reports.dir}"/>
		</junitreport>
	</target>
</project>
